﻿using System;
using Medicalsystem.MCP.FormDesigner.Common;

namespace Medicalsystem.MCP.FormDesigner
{
    /// <summary>
    /// 模板设计器使用
    /// </summary>
    public sealed class SingleList
    {
        private static SingleList _instance;
        private CopyPaste _copyPaste;

        private SingleList()
        {
            _copyPaste = new CopyPaste();
        }

        /// <summary>
        /// 编辑器实例-相关操作变量
        /// </summary>
        public static SingleList Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new SingleList();
                }
                return _instance;
            }
        }

        public delegate void messageHandler(object sender, MessageType e);

        /// <summary>
        /// 控件处理与设计器的交互
        /// </summary>
        public event messageHandler MessageEvent;

        /// <summary>
        /// 选择了某个要添加的控件后，这里保存这个控件的名称
        /// </summary>
        public string ControlName = string.Empty;
        public string AssemblyName = string.Empty;

        /// <summary>
        /// 移动锁定
        /// </summary>
        public bool MoveLock = false;

        /// <summary>
        /// 重置属性-切换模板时
        /// </summary>
        public void Reset()
        {
            ControlName = string.Empty;
            MoveLock = false;
        }

        /// <summary>
        /// 向设计器传递消息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnMessageEvent(Object sender, MessageType e)
        {
            if (MessageEvent != null)
            {
                MessageEvent(sender, e);
            }
        }

        /// <summary>
        /// 粘贴复制
        /// </summary>
        public CopyPaste CopyPaste
        {
            get { return _copyPaste; }
        }

        /// <summary>
        /// 销毁
        /// </summary>
        public void Dispose()
        {
            _instance = null;
        }
    }
}